<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/30
 * Time: 11:54
 */

namespace app\common\controller;


use app\api\controller\Pub;
use app\common\model\CardConsume;
use app\common\model\CardCzgive;
use app\common\model\CardRank;
use app\common\model\CardUserGet;
use app\common\model\Merchant;
use app\common\model\Paylog;
use Wechat\Wxobjopen;

class MachExtend extends Wxoption
{
    //获取门店折扣   门店id和支付金额
    //merchantid     total_fee to add_balance
    public function get_machzk($param){
        //是否有门店折扣
        $param['add_balance'] = $param['total_fee'];
        $is_machzk = 'N';
        if ($param['merchantid']) {
            $Merchant = new Merchant();
            $mach = $Merchant->where(['id' => $param['merchantid']])->find();
            if ($mach){
                if($mach['is_discount'] == 'Y'){
                    $discount = $mach['discount_rate'] / 100;                          //折扣比率
                    $arrs['del_balance'] = $param['add_balance'] * $discount;     //需支付金额
                    //END
                    $datas['yf_price'] = $param['add_balance'];
                    $datas['zk_price'] = $param['add_balance'] - $arrs['del_balance'];      //原金额减去支付金额等于折扣金额
                    $is_machzk = 'Y';
                }else{
                    $datas['yf_price'] = $param['add_balance'];
                    $datas['zk_price'] = 0;
                }
            }else{
                $datas['yf_price'] = $param['add_balance'];
                $datas['zk_price'] = 0;
            }
        }else{
            $datas['yf_price'] = $param['add_balance'];
            $datas['zk_price'] = 0;
        }
        $Paylog = new Paylog();
        $payinfo = $Paylog->where(array('orderid' => $param['orderid']))->find();
        if ($payinfo) {
            $datas['mach_zk'] = $datas['zk_price'];
            $Paylog->where(array('orderid' => $param['orderid']))->update($datas);
        }
        //END
        $datas['is_machzk'] = $is_machzk;
//        $zk_price = $datas['zk_price'];
        $datas['dis_card_zk'] = 0;                                                 //会员折扣
        $datas['vip_card_zk'] = 0;                                                     //等级折扣
        $datas['gel_card_zk'] = 0;
        $datas['mach_zk'] = $datas['zk_price'];
        $datas['del_balance']=$datas['yf_price']-$datas['zk_price'];
        $datas['hx_card'] ="";
        return $datas;
    }

}